package com.zzb.servlet.user;


import com.alibaba.fastjson.JSONObject;
import com.zzb.DTO.ResultDTO;
import com.zzb.VO.UserVO;
import com.zzb.service.UserService;
import com.zzb.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;


@WebServlet("/back/user/delete")
public class UserDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());

        //得到前端数据
        String id = req.getParameter("id");

        //对前端数据进行封装
        UserVO userVO = UserVO.builder()
                .id(Integer.valueOf(id))
                .build();

        //调用服务逻辑
        UserService userService = new UserServiceImpl();
        //得到响应数据
        ResultDTO resultDTO = userService.delete(userVO);
        //将数据响应给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
